package com.jiangchuang.controller;

import com.jiangchuang.domain.Result;
import com.jiangchuang.domain.entity.Activity;
import com.jiangchuang.service.IActivityService;
import com.jiangchuang.service.ICommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RequestMapping("/api")
@Api(tags = "活动管理")
@RestController
public class ActivityController {
    
    @Autowired
    private IActivityService activityService;
    @Autowired
    private ICommonService commonService;

    @ApiOperation(value = "获取最新活动")
    @GetMapping("/getLatestActivity")
    public Result<Activity> getLatestActivity() {
        Activity activity = activityService.getLatestActiveActivity();
        return Result.ok(activity);
    }

    @ApiOperation(value = "获取所有活动")
    @GetMapping("/getAllActivities")
    public Result<List<Activity>> getAllActivities() {
        List<Activity> activities = activityService.getAllActivities();
        return Result.ok(activities);
    }

    @ApiOperation(value = "编辑活动")
    @PutMapping("/updateActivity")
    public Result<Boolean> updateActivity(@RequestBody Activity activity) {
        boolean result = activityService.updateActivity(activity);
        return result ? Result.ok(true) : Result.fail("编辑活动失败");
    }


    @ApiOperation(value = "上传活动图片")
    @PostMapping("/uploadActivityImg")
    private Result<String> uploadActivityImg(Integer aId, MultipartFile img){
        return Result.ok(activityService.uploadActivityImg(aId,img));
    }

}
